﻿using JetBrains.Annotations;

namespace StreetPacMan.Server
{
    public interface IGameRules
    {
        int PointsForEatingGhost { get; }

        //bool IsGhostSeeingPacMan(double pacManLat, double pacManLon, double ghostLat, double ghostLon);
        bool ArePacManAndGhostTouching(double pacManLat, double pacManLon, double ghostLat, double ghostLon);
//        bool ArePacManAndAppleTouching(double pacManLat, double pacManLon, double appleLat, double appleLon);

    }

    [UsedByIoc]
    public class GameRules : IGameRules
    {
        public int PointsForEatingGhost  
        {
            get { return 200; }
        }

        public bool IsGhostSeeingPacMan(double pacManLat, double pacManLon, double ghostLat, double ghostLon)
        {
            return AreCloseWithinXMeters(pacManLat, pacManLon, ghostLat, ghostLon, 50);
        }

        public bool ArePacManAndGhostTouching(double pacManLat, double pacManLon, double ghostLat, double ghostLon)
        {
            return AreCloseWithinXMeters(pacManLat, pacManLon, ghostLat, ghostLon, 15);
        }

        public bool ArePacManAndAppleTouching(double pacManLat, double pacManLon, double appleLat, double appleLon)
        {
            return AreCloseWithinXMeters(pacManLat, pacManLon, appleLat, appleLon, 15);
        }

        private bool AreCloseWithinXMeters(double lat1, double lng1, double lat2, double lng2, int meters)
        {
            //return new Location().AreCloseWithinXMeters(lat1, lng1, lat2, lng2, meters);
            //var distanceInMeters = Math.Sqrt(Math.Pow(lng1 - lng2, 2) + Math.Pow(lat1 - lat2, 2)) * 100000;
            //return distanceInMeters < meters;
        }
    }
}
